// pages/category/category.js
let { getCategoryData } = require('../../api/Category')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goodList: [
      [
        {
        img: "/images/goods01.jpg",
        name: "商品1"
      }, {
        img: "/images/goods01.jpg",
        name: "商品1"
      }, {
        img: "/images/goods01.jpg",
        name: "商品1"
      }, {
        img: "/images/goods01.jpg",
        name: "商品1"
      }, {
        img: "/images/goods01.jpg",
        name: "商品1"
      }, {
        img: "/images/goods01.jpg",
        name: "商品1"
      }, {
        img: "/images/goods01.jpg",
        name: "商品1"
      }],
      [{
        img: "/images/goods02.jpg",
        name: "商品2"
      }, {
        img: "/images/goods02.jpg",
        name: "商品2"
      }, {
        img: "/images/goods02.jpg",
        name: "商品2"
      }, {
        img: "/images/goods02.jpg",
        name: "商品2"
      }, {
        img: "/images/goods02.jpg",
        name: "商品2"
      }, {
        img: "/images/goods02.jpg",
        name: "商品2"
      }, {
        img: "/images/goods02.jpg",
        name: "商品2"
      }]
    ],
    num: 0,
  },
  changeNum(options) {
    let num = options.target.dataset.index;
    // 修改num值
    this.setData({
      num: num
    })
  },
  goDetails(options){
    console.log(this);
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 微信提供api接口，获取系统信息
    // 1.获取数据
    wx.getSystemInfo({
      success: (result) => {
        // console.log(result);
        // console.log(result.windowHeight);
        // 修改data里面数据
        // 调用this.setData();
        // 3.获取数据赋值data静态数据中
        this.setData({
          scrollHeight: result.windowHeight
        })
      }
    })


    // 获取商品分类
    getCategoryData().then(res=>{
      // console.log(res);
      let goodList = res.message;; //商品右侧分类详情
      this.setData({
        goodList,
      })
      // console.log("处理过后的商品列表",goodList);
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let index = wx.getStorageSync("categroyIndex");
    console.log(index);
    this.setData({
      num: index
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})